package com.freework.util.excel.read.service.rowToObject;

import org.apache.commons.beanutils.ConvertUtils;

import com.freework.util.NumberUtil;
import com.freework.util.excel.read.vo.ColVO;

public abstract class AbstractSetValue implements SetValueI {
	public void setValue(Object obj,String value,ColVO vo){
		
		
	
		
		Object  value1=null;
		ValueFormat	valueFormat=vo.getFormat();
		if(valueFormat!=null){
			
			value1=valueFormat.getValue(obj, value, vo);
			 this.setObjValue(obj, value1, vo);
			 return ;
			
		}
		Class clazz=getClass(vo);
		if(clazz==String.class)
			value1=value;
		 value1=ConvertUtils.convert(value,clazz);
		 this.setObjValue(obj, value1, vo);
		
	}
	public void setValue(Object obj,double value,ColVO vo){
		
		
		Object  value1=null;
		ValueFormat	valueFormat=vo.getFormat();
		if(valueFormat!=null){
			value1=valueFormat.getValue(obj, value, vo);
			 this.setObjValue(obj, value1, vo);
			 return ;
			
		}
		Class clazz=getClass(vo);

		if(clazz==String.class)
			value1= String.valueOf(value);
		else
			value1=NumberUtil.doubleToNubmer(value, clazz);
			this.setObjValue(obj, value1, vo);
		
	}
	abstract Class getClass(ColVO vo);
	abstract public void setObjValue(Object obj,Object value,ColVO vo);


}
